package com.jp.knowledge.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;

import com.google.gson.JsonObject;
import com.jp.knowledge.http.HttpHelper;
import com.jp.knowledge.my.adapter.UiFragmentAdapter;
import com.jp.knowledge.my.model.CollectionUiModel;

import java.util.List;

/**
 *
 * @author 528787067@qq.com
 * @date 2017/5/11
 */

public class ProductUIAdapter extends UiFragmentAdapter {

    public ProductUIAdapter(Context context, @NonNull List list) {
        super(context, list);
    }

    public ProductUIAdapter(Context context, @NonNull List list, boolean isIcon) {
        super(context, list, isIcon);
    }

    @Override
    public void updateAdapter(@NonNull List list) {
        super.updateAdapter(list);
    }

    @Override
    public void onClick(View v) {
        int position = (int)v.getTag();
        CollectionUiModel uiModel = getData(position);
        JsonObject param = new JsonObject();
        param.addProperty("token", HttpHelper.token);
        param.addProperty("id", uiModel.getId());
        param.addProperty("type", 15);
        if(uiModel.getIsFollow() == 1) {
            HttpHelper.getInstance(mContext).unCollection(param, position * 10 + COLLECTION_OPERATE_CODE, this);
        } else{
            HttpHelper.getInstance(mContext).collectionHead(param, position * 10 + COLLECTION_OPERATE_CODE, this);
        }
        uiModel.setIsFollow(uiModel.getIsFollow()==1 ? 0 : 1);
        notifyItemChanged(position);
    }
}
